<template>
    <!--生成订单-- 待支付页面 -->
    <view>
        <view class="bg_image">
            <view class="appointment">待支付</view>
            <view class="prompt_font">您的订单还未支付</view>
        </view>
        <view class="card_content card_one">
            <view
                style="display: flex; justify-content: space-between"
                v-if="orderData.deliveryType != 2"
                @click="writeaddress()"
            >
                <view style="width: 90%">
                    <view class="peopinfoContent">
                        <view class="peopinfo">
                            <text>{{ orderData.name }}</text>
                            <text class="phone">{{ orderData.phone }}</text>
                        </view>
                    </view>
                    <view class="addressinfo">
                        <text>
                            <!-- 位置信息 -->
                            {{
                                orderData.addressDistrict
                                    ? orderData.addressDistrict
                                    : ''
                            }}{{ orderData.address ? orderData.address : '' }}
                        </text>
                    </view>
                </view>
                <view style="padding-top: 15rpx">
                    <image
                        style="width: 40rpx; height: 30rpx"
                        src="../../../pagesSub/static/images/icon_right_black.png"
                    ></image>
                </view>
            </view>

            <view class="personal_info pa_top personalfont">
                <text class="peopinfo">就诊人信息</text>
                <view style="display: flex">
                    <text style="font-size: 31rpx">
                        {{ orderData.patientName ? orderData.patientName : '' }}
                        <text style="padding: 0 5rpx">|</text>
                        {{
                            orderData.sex == 1
                                ? '男'
                                : orderData.sex == 2
                                ? '女'
                                : ''
                        }}
                        <text style="padding: 0 5rpx">|</text>
                        {{ orderData.age ? orderData.age : '' }}岁
                    </text>
                </view>
            </view>
        </view>

        <!-- 物流选择 -->
        <view class="card_content" style="width: 84%; display: flex">
            <!-- @click="openPop" -->
            <text style="color: red">*</text>
            <text class="" style="width: 200rpx"> 配送方式 </text>
            <view
                style="
                    width: 75%;
                    display: flex;
                    justify-content: space-between;
                "
            >
                <text class="" style="width: 80%; text-align: right">
                    <!-- 达达 -->
                    {{ logisticsObj[orderData.deliveryType] || '达达' }}
                    <!-- 配送类型 -->
                </text>
            </view>
        </view>

        <!-- 健康防疫 填写体温 -->
        <!-- <temperature
            ref="childer"
            :preventionFlag="orderData.preventionFlag"
            :info="orderData.preventionInfo"
            @send="getTemperature"
            type="detail"
        ></temperature> -->

        <!--医生信息  -->
        <view
            class="card_content card_one"
            style="margin-top: 30rpx"
            v-if="orderData.type == 1"
        >
            <view class="peopinfoContent">
                <view style="float: left">
                    <image
                        style="width: 80rpx; height: 80rpx; border-radius: 50%"
                        :src="orderData.avatar"
                    ></image>
                </view>
                <view class="peopinfo" style="padding-left: 95rpx">
                    <text>{{
                        orderData.doctorName ? orderData.doctorName : ''
                    }}</text>
                    <text style="padding-left: 15rpx">
                        {{ orderData.hosName ? orderData.hosName : '' }}
                    </text>
                </view>
                <view class="addressinfo peopinfo" style="padding-left: 95rpx">
                    <text style="font-size: 28rpx">
                        {{ orderData.jobTitle ? orderData.jobTitle : '' }} |
                        {{ orderData.deptName ? orderData.deptName : '' }}
                    </text>
                </view>
            </view>
        </view>
        <view class="card_content card_one" style="margin-top: 30rpx" v-else>
            <!-- 药店信息 -->
            <view class="peopinfoContent">
                <view style="float: left">
                    <image
                        style="width: 80rpx; height: 80rpx; border-radius: 50%"
                        :src="orderData.storeLogo"
                    ></image>
                </view>
                <view class="peopinfo" style="padding-left: 95rpx">
                    <text>{{
                        orderData.doctorName ? orderData.doctorName : ''
                    }}</text>
                    <text style="padding-left: 15rpx">
                        {{ orderData.storeName ? orderData.storeName : '' }}
                    </text>
                </view>
                <view class="addressinfo peopinfo" style="padding-left: 95rpx">
                    <!-- v-if="orderData.workTime"  -->
                    <text style="font-size: 28rpx; color: #d57667">
                        营业时间:{{
                            orderData.workTime ? orderData.workTime : ''
                        }}（营业时间内可以配送）
                    </text>
                </view>
                <view class="addressinfo peopinfo" style="padding-left: 95rpx">
                    <text style="font-size: 28rpx">
                        {{
                            orderData.storeAddress ? orderData.storeAddress : ''
                        }}
                    </text>
                </view>
            </view>
        </view>
        <view class="durgName pad30" style="text-align: right; color: red">
            注：仅带有
            <image
                class="yibaoTips"
                style="margin: 0"
                src="../../../static/images/chs.png"
            ></image>
            <!-- <text class="yibaoTips">医保</text> -->
            标志的药品支持医保支付
        </view>
        <view class="card_content">
            <view class="peopinfo" style="display: flex">
                <image
                    style="width: 45rpx; height: 45rpx"
                    src="../../../pagesSub/static/images/icon_h_chu@2x.png"
                ></image>
                <view>{{ type == 2 ? '处方信息' : '订单信息' }}</view>
            </view>
            <view>
                <view style="margin-top: 30rpx">
                    <text style="font-size: 32rpx">
                        {{
                            orderData.pharmacyName ? orderData.pharmacyName : ''
                        }}
                    </text>
                </view>
                <view
                    class="medical_content"
                    v-for="(
                        data, index
                    ) in orderData.wxReserveDrugResponseBodies"
                    :key="index"
                >
                    <view class="medical_img">
                        <image :src="data.drugImg"></image>
                    </view>
                    <view class="medical_right">
                        <view class="medical_title">
                            <view>
                                <view class="medicalName">
                                    <view class="durgName">
                                        <image
                                            class="yibaoTips"
                                            v-if="(data.medicalItemCode)&&data.medicalFlag == 1
                                            "
                                            src="../../../static/images/chs.png"
                                        ></image>
                                        <!-- <text class="yibaoTips" v-if="data.medicalItemCode">医保</text> -->
                                        {{ data.drugName }}
                                    </view>
                                </view>
                                <view class="specification gray_font">
                                    规格：{{
                                        data.drugSpecification
                                            ? data.drugSpecification
                                            : '暂无规格'
                                    }}
                                </view>
                            </view>
                            <view class="medicalName"
                                >x{{ data.drugCount || 1 }}</view
                            >
                        </view>
                        <view class="medical_price"
                            >￥{{ data.drugPrice || 0 }}</view
                        >
                    </view>
                </view>
            </view>
        </view>
        <view class="card_content">
            <view class="personal_info">
                <text class="specification gray_font">开具发票</text>
                <view
                    class="specification"
                    style="display: flex"
                    @click="toggle('bottom')"
                >
                    <view
                        v-if="orderData.billType == '' || orderData.isBill == 1"
                    >
                        <text style="font-size: 31rpx">本次不开具发票</text>
                    </view>
                    <view v-if="orderData.billType == 1">
                        <text style="font-size: 31rpx">普通发票-个人</text>
                    </view>
                    <view v-if="orderData.billType == 2">
                        <text style="font-size: 31rpx">普通发票-公司</text>
                    </view>
                    <image
                        style="width: 40rpx; height: 30rpx; margin-top: 5rpx"
                        src="../../../pagesSub/static/images/icon_right_black.png"
                    ></image>
                </view>
            </view>
            <view v-if="orderData.billType == 1">
                <view class="specification">
                    发票抬头：{{ orderData.rise ? orderData.rise : '' }}
                </view>
            </view>
            <view v-if="orderData.billType == 2">
                <view class="specification">
                    发票抬头：{{ orderData.unitName ? orderData.unitName : '' }}
                </view>
                <view class="specification">
                    纳税人识别号：{{
                        orderData.taxPayerNo ? orderData.taxPayerNo : ''
                    }}
                </view>
            </view>
        </view>
        <view style="padding-bottom: 200rpx" >
            <view class="card_content"  >
                <view class="personal_info">
                    <text class="specification gray_font">商品总金额</text>
                    <text class="medicalName">
                        ￥{{
                            orderData.commodityPrice
                                ? orderData.commodityPrice
                                : '0'
                        }}
                    </text>
                </view>
                <view class="personal_info">
                    <text class="specification gray_font">配送费</text>
                    <text class="medicalName">
                        ￥{{ orderData.deliveryFee ? orderData.deliveryFee : '0' }}
                    </text>
                </view>
                <view class="personal_info">
                    <text class="specification gray_font">优惠金额</text>
                    <text class="medicalName">
                        ￥{{ orderData.couponPrice ? orderData.couponPrice : '0' }}
                    </text>
                </view>
                <view class="personal_info">
                    <text class="specification gray_font">实付款</text>
                    <text class="real_payment">
                        ￥{{ allPrice ? allPrice : orderData.actualPayment }}
                    </text>
                </view>
                <view class="personal_info" v-if="orderValue == 1">
                    <text class="specification gray_font">医保余额</text>
                    <text class="medicalName">￥{{ yibaoInfo.ye || '0' }}</text>
                </view>

                <view class="personal_info" >
                    <text class="specification gray_font">支付方式</text>
                    <text class="medicalName">{{payType[orderData.payFlag]}}</text>
                </view>
            </view>
        </view>

        <!-- <hover-ball /> -->
        <!-- isMedicalSupport 是否支持医保支付(0是1否)  weiFlag 是否支持微信支付(0是1否) -->
        <!-- <view>
            <view style="margin-left: 60rpx">选择支付方式</view>
            <view style="padding-bottom: 200rpx">
                <view class="card_content" style="margin-bottom: 100rpx">
                    <radio-group class="radio-wrap" @change="hosChange">
                        <label for="" v-if="isDongyingStore != 0">
                            <view
                                class="personal_info"
                                style="
                                    padding-bottom: 20rpx;
                                    border-bottom: 1px solid #fbf5f5;
                                "
                                v-if="orderData.weiFlag != 1"
                            >
                                <view style="display: flex">
                                    <image
                                        style="width: 60rpx; height: 48rpx"
                                        src="../../../pagesSub/static/images/wxpay.png"
                                    ></image>
                                    <view>
                                        <text
                                            class="specification"
                                            style="margin-left: 20rpx"
                                        >
                                            微信支付<text
                                                v-if="
                                                    isShowCoupon.includes('0')
                                                "
                                                style="font-size: 24rpx"
                                                >(可享受满减优惠)</text
                                            >
                                        </text>
                                    </view>
                                </view>
                                <radio
                                    :disabled="!(orderData.payFlag == '0')"
                                    value="0"
                                    :checked="wxPay == 0"
                                    color="#4ccdbc"
                                    style="transform: scale(1)"
                                />
                            </view>
                            <view
                                class="personal_info"
                                style="
                                    padding: 20rpx 0;
                                    border-bottom: 1px solid #fbf5f5;
                                "
                                v-if="orderData.isMedicalSupport != 1"
                            >
                                <view style="display: flex">
                                    <image
                                        style="width: 60rpx; height: 44rpx"
                                        src="../../../static/images/chs.png"
                                    ></image>
                                    <view>
                                        <text
                                            class="specification"
                                            style="margin-left: 20rpx"
                                        >
                                            医保支付<text
                                                v-if="
                                                    isShowCoupon.includes('1')
                                                "
                                                style="font-size: 24rpx"
                                                >(可享受满减优惠)</text
                                            >
                                        </text>
                                    </view>
                                </view>
                                <radio
                                    :disabled="!(orderData.payFlag == '1')"
                                    value="1"
                                    :checked="wxPay == 1"
                                    color="#4ccdbc"
                                    style="transform: scale(1)"
                                />
                            </view>
                        </label>

                        <view v-if="isDongyingStore == 0">
                            <view
                                class="personal_info"
                                style="
                                    padding-bottom: 20rpx;
                                    border-bottom: 1px solid #fbf5f5;
                                "
                            >
                                <view style="display: flex">
                                    <image
                                        style="width: 60rpx; height: 56rpx"
                                        src="../../../pagesSub/static/images/zhPay.png"
                                    ></image>
                                    <view>
                                        <text
                                            class="specification"
                                            style="margin-left: 20rpx"
                                            >农行支付<text
                                                v-if="
                                                    isShowCoupon.includes(
                                                        'nonghang'
                                                    )
                                                "
                                                style="font-size: 24rpx"
                                                >(可享受满减优惠)</text
                                            >
                                        </text>
                                    </view>
                                </view>
                                <radio
                                    :disabled="
                                        !(orderData.payFlag == 'nonghang')
                                    "
                                    value="nonghang"
                                    :checked="wxPay == 'nonghang'"
                                    color="#4ccdbc"
                                    style="transform: scale(1)"
                                />
                            </view>
                            <view
                                class="personal_info"
                                style="
                                    padding: 20rpx 0;
                                    border-bottom: 1px solid #fbf5f5;
                                "
                            >
                                <view style="display: flex">
                                    <image
                                        style="width: 60rpx; height: 44rpx"
                                        src="../../../pagesSub/static/images/dyyb1.png"
                                    ></image>
                                    <view>
                                        <text
                                            class="specification"
                                            style="margin-left: 20rpx"
                                        >
                                            东营医保<text
                                                v-if="
                                                    isShowCoupon.includes(
                                                        '市医保'
                                                    )
                                                "
                                                style="font-size: 24rpx"
                                                >(可享受满减优惠)</text
                                            >
                                        </text>
                                    </view>
                                </view>
                                <radio
                                    :disabled="!(orderData.payFlag == '市医保')"
                                    value="市医保"
                                    :checked="wxPay == '市医保'"
                                    color="#4ccdbc"
                                    style="transform: scale(1)"
                                />
                            </view>
                            <view
                                class="personal_info"
                                style="
                                    padding: 20rpx 0;
                                    border-bottom: 1px solid #fbf5f5;
                                "
                            >
                                <view style="display: flex">
                                    <image
                                        style="width: 60rpx; height: 48rpx"
                                        src="../../../pagesSub/static/images/oil1.png"
                                    ></image>
                                    <view>
                                        <text
                                            class="specification"
                                            style="margin-left: 20rpx"
                                        >
                                            油田医保<text
                                                v-if="
                                                    isShowCoupon.includes(
                                                        '省医保'
                                                    )
                                                "
                                                style="font-size: 24rpx"
                                                >(可享受满减优惠)</text
                                            >
                                        </text>
                                    </view>
                                </view>
                                <radio
                                    :disabled="!(orderData.payFlag == '省医保')"
                                    value="省医保"
                                    :checked="wxPay == '省医保'"
                                    color="#4ccdbc"
                                    style="transform: scale(1)"
                                />
                            </view>
                            <view
                                v-if="orderData.weiFlag != 1"
                                class="personal_info"
                                style="
                                    padding: 20rpx 0;
                                    border-bottom: 1px solid #fbf5f5;
                                "
                            >
                                <view style="display: flex">
                                    <image
                                        style="width: 60rpx; height: 48rpx"
                                        src="../../../pagesSub/static/images/wxpay.png"
                                    ></image>
                                    <view>
                                        <text
                                            class="specification"
                                            style="margin-left: 20rpx"
                                        >
                                            微信支付<text
                                                v-if="
                                                    isShowCoupon.includes('0')
                                                "
                                                style="font-size: 24rpx"
                                                >(可享受满减优惠)</text
                                            >
                                        </text>
                                    </view>
                                </view>
                                <radio
                                    :disabled="!(orderData.payFlag == '0')"
                                    value="0"
                                    :checked="wxPay == '0'"
                                    color="#4ccdbc"
                                    style="transform: scale(1)"
                                />
                            </view>
                        </view>
                    </radio-group>
                </view>
            </view>
        </view> -->
        <!-- <view v-if="isDongyingStore == 0">
        <view style="margin-left: 60rpx">选择支付方式</view>
        <view style="padding-bottom:200rpx;">
            <view class="card_content" style="margin-bottom: 100rpx">
                <radio-group class="radio-wrap" @change="hosChange">
                    <label for="">
                      
                </radio-group>
            </view>
        </view>
    </view> -->
        <!-- <view class="customerService">
            <image @click="Service" src="../../../pagesSub/static/images/btn_h_ke@2x.png"></image>
        </view> -->
        <view class="payment_button">
        <!-- v-if="orderData.weiFlag != 1 || orderData.isMedicalSupport != 1" -->
            <view class="combined">
                合计:
                <text class="combined_money">
                    ￥{{ allPrice }}
                    <!-- {{ orderData.actualPayment ? orderData.actualPayment : ''}} -->
                </text>
            </view>
            <button
                :disabled="extraction"
                class="immediate"
                @click="getOrderPay"
            >
                立即支付
            </button>
        </view>
        <!-- 发票 -->
        <uni-popup ref="popup" background-color="#fff" :mask-click="false">
            <view style="padding: 30rpx">
                <view class="colse_content">
                    <image
                        @click="closeinvoice"
                        style="width: 50rpx; height: 50rpx; float: right"
                        src="../../../pagesSub/static/images/icon_close_gray.png"
                    ></image>
                </view>

                <view class="personal_info">
                    <text class="specification">发票类型</text>
                    <text class="specification gray_font">普通发票</text>
                </view>
                <view class="personal_info">
                    <text class="specification">开具发票</text>
                    <view>
                        <switch
                            :checked="orderData.isBill == 0"
                            color="#4CCCBF"
                            style="margin-top: -8rpx; transform: scale(0.7)"
                            @change="changeInvoice"
                        />
                    </view>
                </view>
                <view v-if="orderData.isBill == 0">
                    <text class="specification">发票抬头</text>
                    <view class="invoice">
                        <view
                            style="margin-right: 15rpx"
                            :class="orderData.billType == 1 ? 'tag' : ''"
                            @click="invoiceType(1)"
                            class="bth_green"
                        >
                            个人
                        </view>
                        <view
                            :class="orderData.billType == 2 ? 'tag' : ''"
                            @click="invoiceType(2)"
                            class="bth_green"
                        >
                            公司
                        </view>
                    </view>
                    <view class="invoiceInput" v-if="orderData.billType == 1">
                        <view style="display: flex">
                            <view
                                style="
                                    color: #ff5100;
                                    font-size: 40rpx;
                                    margin-right: 5rpx;
                                "
                            >
                                *
                            </view>
                            <uni-easyinput
                                style="width: 100%"
                                v-model="orderData.rise"
                                placeholder="请填写开具发票人的姓名"
                            ></uni-easyinput>
                        </view>
                    </view>
                    <view class="invoiceInput" v-if="orderData.billType == 2">
                        <view>
                            <view style="display: flex">
                                <view
                                    style="
                                        color: #ff5100;
                                        font-size: 40rpx;
                                        margin-right: 5rpx;
                                    "
                                >
                                    *
                                </view>
                                <uni-easyinput
                                    style="width: 100%"
                                    v-model="orderData.unitName"
                                    placeholder="请填写单位名称"
                                ></uni-easyinput>
                            </view>
                        </view>
                        <view style="margin-top: 20rpx">
                            <view style="display: flex">
                                <view
                                    style="
                                        color: #ff5100;
                                        font-size: 40rpx;
                                        margin-right: 5rpx;
                                    "
                                >
                                    *
                                </view>
                                <uni-easyinput
                                    style="width: 100%"
                                    type="number"
                                    v-model="orderData.taxPayerNo"
                                    placeholder="请填写纳税人识别号"
                                ></uni-easyinput>
                            </view>
                        </view>
                    </view>
                </view>
                <button @click="saveinvoice" class="btn_invoice" type="default">
                    修改
                </button>
            </view>
        </uni-popup>

        <!-- 立即支付确认框  不退不换 -->
        <uni-popup ref="notChangePop" type="dialog">
            <view class="inputDialog">
                <view class="title">
                    由于药品属于特殊商品，一经售出，概不退换
                </view>

                <view class="button-bottom">
                    <view class="cancel" @click="closeTem">取消</view>
                    <view @click="toOrderPay()" class="green_words">确定</view>
                </view>
            </view>
        </uni-popup>

        <!-- 物流弹窗 -->
        <!-- <uni-popup ref="logisticsPopup" type="center">
        <view class="dialogDiangnosis" v-show="expressTypeList.length >= 0">
            <scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" @scroll="scroll">
                <radio-group class="block" @change="changeCheckbox">
                    <label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in expressTypeList" :key='index'>
                        <uni-list-item :title="item.name" :border="false">
                            <template v-slot:footer>
                                <radio :value="String(item.type)" color="#4ccdbc" :checked="index== current" />
                            </template>
                        </uni-list-item>
                    </label>
                </radio-group>
            </scroll-view>

            <view class="btn_style">
                <button class="arc_button width" style="background: -webkit-linear-gradient(#77E2A4, #4CCDBC) !important;width:200rpx;line-height: 60rpx; height:60rpx; border-radius: 30rpx;" type="primary" @click="saveDiagnosis">确定</button>
            </view>
        </view>
    </uni-popup> -->
        <!-- 优惠券提示框 -->
        <uni-popup ref="couponPop">
            <view class="inputDialog">
                <view class="title">
                    {{ couponPopTips }}
                </view>
                <view class="button-bottom">
                    <view class="cancel" @click="closeCoupon">取消</view>
                    <view @click="closeCoupon" class="green_words">确定</view>
                </view>
            </view>
        </uni-popup>
        <!-- <couponPop ref="couponChild" type="waitPay" wxPay=""
            ></couponPop> -->
    </view>
</template>

<script>
import { orderdetail, updatebill, deletebill } from '@/api/prescribing.js';
import {
    wechatOrderPay,
    paySuccess,
    yibaoOrderPay,
    yibaoMoney,
    getIsDongyingStore,
    nonghangOrderPay,
    // getCouponPayType,
} from '@/api/consult.js';
import { getFreight } from '@/api/order.js';
import store from '@/store';

// import hoverBall from '@/components/hover-ball/hover-ball.vue';
// import couponPop from 'pagesSub/components/couponPop/index.vue';

import temperature from 'pagesSub/components/temperature/temperature';
export default {
    components: {
        // hoverBall,
        temperature,
        // couponPop,
    },
    data() {
        return {
            payType: {
                'nonghang':'农行支付',
                '0':'微信支付',
                '1':'医保支付',
                '省医保':'油田医保',
                '市医保':'东营医保',
            },
            isShowCoupon: [], //可使用优惠券的支付方式
            radioDisabled: true, //支付按钮是否置灰
            couponPopTips: '使用本券请选择中国农业银行支付', //优惠券提示文案

            isDongyingStore: 1, //0是东营 1：非东营
            allPrice: 0, //总价
            logisticsObj: {
                1: '达达',
                2: '到店自提',
            }, //已选物流名称
            logisticsType: '1', //配送类型
            current: 0, //选中的下标
            expressIndex: 0, //快递列表的下标
            expressTypeList: [
                {
                    name: '达达',
                    type: '1',
                },
                {
                    name: '到店自提',
                    type: '2',
                },
            ], // 快递类型列表

            yibaoInfo: {}, // 医保信息
            temperature: '', //体温
            orderValue: '0', //支付方式 0：微信 1：医保 省医保： 油田医保 市医保：东营医保
            wxPay: '0', // 选中的支付方式 0：微信 1：医保 省医保： 油田医保 市医保：东营医保 nonghagn:农行支付
            extraction: false,
            type: '', // 上个页面传过来的类型  // type ==2 预约购药  type==4 扫码购药  6--开具处方  5--商城
            orderid: '',
            orderData: {},
            checkstatus: 1,
            // longitude:'',//
            // latitude:'' ,//
        };
    },
    onLoad(option) {
        // type ==2 预约购药  type==4 扫码购药  6--开具处方
        if (option.item) {
            this.orderid = option.item;
            this.type = option.type;
        }
        // this.orderdetails()
    },
    // onShow() {
    // },
    onShow: function () {
        this.getIsDontying(); // 查询是否是东营药店

        this.orderdetails(); //订单详情
        // this.freight();
    },
    methods: {
        // // 查询满减券支付方式
        // getCouponPaytype() {
        //     let storeId = this.orderData.pharmacyId;
        //     getCouponPayType(storeId)
        //         .then((res) => {
        //             if (res.code == 200) {
        //                 this.isShowCoupon = res.data; // true;
        //                 console.log(
        //                     this.isShowCoupon,
        //                     '9999-----优惠券支付方式'
        //                 );
        //             }
        //         })
        //         .catch((err) => {
        //             uni.showToast({
        //                 title: err,
        //                 icon: 'none',
        //                 duration: 3000,
        //             });
        //         });
        //     // this.isShowCoupon = ['nonghang','市医保','省医保']

        //     //// 1农行支付2东营医保3油田医保4微信支付5医保支付
        //     // 前端映射一下
        //     // let typeMap = {
        //     //     1:'nonghang',
        //     //     2:'市医保',
        //     //     3:'省医保',
        //     //     4:'0', //微信支付
        //     //     5:'1' //医保支付
        //     // }
        //     // // 接口取的type
        //     // let type = [1,2,3] //res.data // [1,2]
        //     // type.map(item=> this.isShowCoupon.push(typeMap[item]) )
        // },
        // 获取是否是东营药店
        getIsDontying() {
            getIsDongyingStore(this.orderid)
                .then((res) => {
                    // console.log(res,'获取是否是东营药店99999')
                    this.isDongyingStore = res.data;
                })
                .catch((err) => {
                    this.$util.Tips({
                        title: err,
                        icon: 'none',
                        duration: 3000,
                    });
                });
        },
        // 查询运费
        freight(obj) {
            // let storeId = store.state.app.storeId //药店id

            getFreight(obj)
                .then((res) => {
                    console.log(res, 'res运费结果');
                    if (res.code == 200) {
                        this.orderData.deliveryFee = res.data.deliveryFee;
                        this.orderData.cityCode = res.data.cityCode;
                        this.orderData.shopNo = res.data.shopNo;
                        this.allPrice =  this.$util.$h.Sub(this.$util.$h.Add(
                            this.orderData.deliveryFee,this.orderData.commodityPrice
                        ),this.orderData.couponPrice) //|| res.data.actualPayment
                    // console.log(this.allPrice,'查完运费的总价999---')
                        
                        // Number(this.orderData.deliveryFee) +
                            // Number(this.orderData.commodityPrice) -
                            // Number(this.orderData.couponPrice); 
                            //合计 = 配送费+商品总金额-优惠金额
                    } else {
                        this.$util.Tips({
                            title: res.msg,
                            icon: 'none',
                            duration: 3000,
                        });
                    }
                })
                .catch((err) => {
                    this.$util.Tips({
                        title: err,
                        icon: 'none',
                        duration: 3000,
                    });
                });
        },

        //   获取子组件的体温
        getTemperature(value) {
            this.temperature = value;
            // console.log(this.temperature, '输入的温度999---父组件里看到的');
        },
        // 关闭优惠券提示文案对话框
        closeCoupon() {
            // this.selectId = '';
            // this.wxPay='nonghang'
            // this.orderValue='nonghang'
            // console.log(this.wxPay,'wxpay--', this.orderValue,'关闭的选中---')

            this.$refs.couponPop.close();
        },
        //查询医保余额
        getYibaoMoney() {
             let storeId = this.orderData.pharmacyId;
            // 医保支付之前需要实名认证，
            yibaoMoney(storeId)
                .then((res) => {
                    this.yibaoInfo = res.data;
                    // console.log(this.yibaoInfo, res.data,'医保余额999--')
                    // this.yibaoBalance = res.data.ye
                    // 判断余额够不够 不够的话不让医保支付
                    if (this.yibaoInfo.ye < this.orderData.actualPayment) {
                        return uni.showToast({
                            title: '医保余额不足，请更换支付方式',
                            icon: 'none',
                            duration: 3000,
                        });
                    }
                    // console.log(res, '是否认证及医保信息9999----');
                })
                .catch((err) => {
                    this.yibaoInfo.ye = 0;
                    this.$util.Tips({
                        title: err,
                        duration: 3000,
                    });
                });
        },
        // // 支付方式切换
        // hosChange(val) {
        //     if (this.orderData.couponPrice != '0') {
        //         // 使用了优惠券
        //         if (val.target.value == 'nonghang') {
        //             // 选择的时农行支付
        //             this.orderValue = val.target.value;
        //             this.wxPay = val.target.value;
        //         } else {
        //             // this.orderValue = 'nonghang';
        //             // this.wxPay = 'nonghang'
        //             // console.log(this.wxPay,'wxpay--', this.orderValue,'打开的选中---')
        //             // this.$refs.couponPop.open();
        //         }
        //     } else {
        //         this.orderValue = val.target.value;
        //     }

        //     // let patientId = this.orderData.patientId;
        //     let storeId = this.orderData.pharmacyId;
        //     // 如果是东营药店 orderValue = "省医保"“市医保” 不需要查询医保余额
        //     if (this.orderValue == 1) {
        //         // 医保支付之前需要实名认证，
        //         yibaoMoney(storeId)
        //             .then((res) => {
        //                 this.yibaoInfo = res.data;
        //                 // console.log(this.yibaoInfo, res.data,'医保余额999--')
        //                 // this.yibaoBalance = res.data.ye
        //                 // 判断余额够不够 不够的话不让医保支付
        //                 if (this.yibaoInfo.ye < this.orderData.actualPayment) {
        //                     return uni.showToast({
        //                         title: '医保余额不足，请更换支付方式',
        //                         icon: 'none',
        //                         duration: 3000,
        //                     });
        //                 }
        //                 console.log(res, '是否认证及医保信息9999----');
        //             })
        //             .catch((err) => {
        //                 this.yibaoInfo.ye = 0;
        //                 this.$util.Tips({
        //                     title: err,
        //                     duration: 3000,
        //                 });
        //             });
        //         // 认证过的话显示医保的余额
        //         // this.yibaoBalance
        //         // 没实名的话 跳转到编辑就诊人信息页面
        //     }
        // },
        invoiceType(type) {
            this.orderData.billType = type;
        },
        //发票修改
        saveinvoice() {
            let _this = this;
            if (
                _this.orderData.billType == '' ||
                _this.orderData.billType == null
            ) {
                uni.showToast({
                    title: '请选择发票类型',
                    icon: 'none',
                    duration: 3000,
                });
                return;
            }
            if (_this.orderData.billType == 1) {
                _this.orderData.unitName == '';
                _this.orderData.taxPayerNo == '';
                if (
                    _this.orderData.rise == '' ||
                    _this.orderData.rise == null
                ) {
                    uni.showToast({
                        title: '请填写发票抬头',
                        icon: 'none',
                        duration: 3000,
                    });
                    return;
                }
            }
            if (_this.orderData.billType == 2) {
                _this.orderData.rise == '';
                if (
                    _this.orderData.unitName == '' ||
                    _this.orderData.unitName == null ||
                    _this.orderData.taxPayerNo == '' ||
                    _this.orderData.taxPayerNo == null
                ) {
                    uni.showToast({
                        title: '请填写发票信息',
                        icon: 'none',
                        duration: 3000,
                    });
                    return;
                }
            }

            updatebill({
                id: _this.orderid,
                billType: _this.orderData.billType,
                rise: _this.orderData.rise,
                unitName: _this.orderData.unitName,
                taxPayerNo: _this.orderData.taxPayerNo,
            })
                .then((res) => {
                    if (res.code == 200) {
                        uni.showToast({
                            title: '修改成功',
                            duration: 3000,
                        });
                        this.$refs.popup.close();
                        this.orderdetails();
                    }
                })
                .catch((err) => {
                    console.log('错误#', err);
                    this.$util.Tips({
                        title: err,
                    });
                });
            // console.log("&&&&发票信息",JSON.stringify(_this.orderData))
        },
        // 开具发票按钮
        changeInvoice(e) {
            let _this = this;
            if (e.target.value) {
                // console.log("^^^^00000")
                _this.orderData.isBill = 0;
            } else {
                // console.log("^^^^111111")
                _this.orderData.isBill = 1;
                deletebill(_this.orderid)
                    .then((res) => {
                        if (res.code == 200) {
                            uni.showToast({
                                title: '修改成功',
                                duration: 3000,
                            });
                            this.$refs.popup.close();
                            this.orderdetails();
                        }
                    })
                    .catch((err) => {
                        console.log('错误#', err);
                    });
            }
        },
        closeinvoice() {
            this.$refs.popup.close();
            this.orderdetails();
        },
        toggle(type) {
            this.type = type;
            // open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
            this.$refs.popup.open(type);
        },
        writeaddress() {
            this.orderData.region = this.orderData.addressDistrict;
            let items = encodeURIComponent(JSON.stringify(this.orderData));
            uni.navigateTo({
                //   url: `/pagesSub-My/my/addressDetails?items=${items}&orderId=${this.orderid}`,
                url: `/pagesSub-My/my/orderAddress?items=${items}&orderId=${this.orderid}&addressId=${this.orderData.addressId}`,
            });
        },
        Service() {
            uni.navigateTo({
                url: `/pagesSub-My/my/customerService`,
            });
        },
        orderdetails() {
            let _this = this;
            uni.showLoading({
                title: '加载中',
            });
            orderdetail(_this.orderid)
                .then((res) => {
                    _this.orderData = res.data;
                    // console.log(res.data,'详情返回的data----')
                    // 查询满减券支付方式
                    // this.getCouponPaytype()
                    // if(res.data.payFlag)
                    this.wxPay = res.data.payFlag; //默认选中详情中的支付方式 ，其他支付方式置灰
                    this.orderValue = res.data.payFlag;
                    if (res.data.payFlag == 1) {
                        // 医保支付 查询余额
                        this.getYibaoMoney();
                    }
                    // if (res.data.couponPrice != '0') {
                    //     // 选了优惠券，只能用农行支付
                    //     this.wxPay = 'nonghang';
                    //     this.orderValue = 'nonghang';
                    //     this.radioDisabled = true;
                    // } else {
                    //     if (this.isDongyingStore == 0) {
                    //         this.orderValue = 'nonghang';
                    //         this.wxPay = 'nonghang'; // res.data.payType || //东营药店的话默认回显农行支付
                    //     } else {
                    //         this.orderValue = 0;
                    //         this.wxPay = 0;
                    //         //  res.data.payType || 0; //回显支付方式
                    //         this.radioDisabled = false;
                    //     }
                    // }
                    this.logisticsType = res.data.deliveryType;
                    this.allPrice = this.$util.$h.Sub(
                        this.$util.$h.Add(
                            this.orderData.commodityPrice,
                            res.data.deliveryFee
                        ),
                        res.data.couponPrice
                    );
                    console.log(this.allPrice,'总价999---')

                    // (Number(_this.orderData.commodityPrice) * 100 +
                    //     Number(res.data.deliveryFee) * 100 -
                    //     Number(res.data.couponPrice) * 100) /
                    // 100; //总金额= 商品总金额+配送费-优惠金额
                    // console.log("订单详情",JSON.stringify(_this.orderData))
                    uni.hideLoading();
                    var obj = {
                        longitude: this.orderData.longitude,
                        latitude: this.orderData.latitude,
                        recieveName: this.orderData.name,
                        recievePhone: this.orderData.phone,
                        recieveAddress: this.orderData.addressDistrict,
                        storeId: store.state.app.storeId, //药店id
                    };
                    if (res.data.deliveryType && res.data.deliveryType != 2) {
                        // 非自提需查询运费
                        this.freight(obj); //查询运费
                    }
                })
                .catch((err) => {
                    uni.hideLoading();
                    _this.$util.Tips({
                        title: err,
                    });
                    console.log('错误#', err);
                });
        },

        // 取消支付弹窗
        closeTem() {
            this.$refs.notChangePop.close();
            // this.doctorinfo()
        },
        //去支付确认框
        toOrderPay() {
            let _this = this;
            let orderNo = _this.orderid;

            this.$refs.notChangePop.close();
            uni.showLoading({
                title: '加载中',
            });
            _this.extraction = true;
            let params = {};
            if (this.logisticsType == 1) {
                // 快递配送
                params = {
                    deliveryType: this.logisticsType, //快递类型
                    orderId: orderNo,
                    cityCode: _this.orderData.cityCode,
                    shopNo: _this.orderData.shopNo,
                    deliveryFee: _this.orderData.deliveryFee, // 配送费
                    longitude: this.orderData.longitude,
                    latitude: this.orderData.latitude,
                    spbillCreateIp: '',
                };
            } else if (this.logisticsType == 2) {
                // 自提
                params = {
                    deliveryType: this.logisticsType, //快递类型
                    orderId: orderNo,
                    deliveryFee: 0,
                    spbillCreateIp: '',
                };
            }
            console.log(params, this.orderValue, '9999----支付方式');
            // return
            //   微信支付：0 、 医保支付：1 线下不需要
            if (
                _this.orderValue == 1 ||
                _this.orderValue == '省医保' ||
                _this.orderValue == '市医保'
            ) {
                // 医保支付
                this.yibaoPay(orderNo, params);
            } else if (_this.orderValue == 'nonghang') {
                this.nhPay(orderNo, params);
            } else {
                //   微信支付
                this.getOrderWxPay(orderNo, params);
            }
        },
        // 立即支付
        getOrderPay: function () {
            let _this = this;
            if (!this.wxPay) {
                return uni.showToast({
                    title: '请选择支付方式',
                    icon: 'none',
                    duration: 3000,
                });
            }
            // // 提示框 不退换
            this.$refs.notChangePop.open();
        },
        // 农行支付
        // nonghangOrderPay
        nhPay(orderNo, params) {
            params = {
                ...params,
                uuid: this.orderData.uuid, //优惠券的uuid
            };
            // 调用农行支付
            nonghangOrderPay(params)
                .then((res) => {
                    this.bankUrl = res.data;
                    console.log(res.data, '要跳转的url');
                    let url = encodeURIComponent(JSON.stringify(res.data));
                    console.log(res.data, url, '要跳转的url');

                    // 关闭当前页面跳转到支付页面
                    uni.redirectTo({
                        url: `/pagesSub/homePage/prescribing/webView?url=${url}`, //res.data,
                    });
                    uni.hideLoading();
                })
                .catch((err) => {
                    uni.showToast({
                        title: err,
                        icon: 'none',
                        duration: 3000,
                    });
                });
        },
        // 医保支付
        yibaoPay(orderNo, params) {
            let _this = this;
            // 判断余额够不够 .话不让医保支付
            if (this.yibaoInfo.ye < this.orderData.actualPayment) {
                _this.extraction = false;

                return uni.showToast({
                    title: '医保余额不足，请更换支付方式',
                    icon: 'none',
                    duration: 3000,
                });
            }
            // 非东营的医保支付入参
            if (this.isDongyingStore == 1) {
                params = {
                    ...params,
                    medicalType: this.yibaoInfo.sbjgbh, //医保类型
                };
            } else {
                params = {
                    ...params,
                    medicalType: this.orderValue, //医保类型
                };
            }
            params = {
                ...params,
                uuid: this.orderData.uuid, //优惠券的uuid
            };
            yibaoOrderPay(params)
                .then((res) => {
                    _this.extraction = false;
                    uni.hideLoading();
                    let data = res.data;
                    //   console.log(res.data, '医保支付的预支付接口返回数据9999---')
                    // return
                    /**
                     *  appId: "wxe9ad2ec23f63e83b"
                        dyfid: "1636536657354uc3zOLMMCK9dIksQB"
                        errorcode: "0"
                        errortext: ""
                        totalfee: 1.1
                        tradeno: "MPC2022030900432613JNSYBJ"
                        ydbh: "012961"
                    */
                    wx.navigateToMiniProgram({
                        appId: data.appId, // 'wxe9ad2ec23f63e83b', //第三方小程序的appid
                        path: 'pages/index/index',
                        extraData: {
                            tradeno: data.tradeno, // 'MPC2022030700432067JNSYBJ', //'MPC20200403111232001',  //平台订单号
                            dyfid: data.dyfid, // 调用方ID（平台统一分配）
                            ydbh: data.ydbh, // '012961', // 药店编号
                        },
                        envVersion: 'trial', // develop:开发版，trial体验版，release正式版

                        fail(res) {
                            //关闭当前页面跳转至订单状态
                            if (
                                res.errMsg ==
                                'navigateToMiniProgram:fail cancel'
                            ) {
                                _this.extraction = false;
                                return _this.$util.Tips({
                                    title: '取消支付',
                                    icon: 'none',
                                });
                            }
                            //  // errMsg: "navigateToMiniProgram:fail cancel"
                        },
                    });
                })
                .catch((err) => {
                    uni.hideLoading();
                    _this.extraction = false;
                    uni.showToast({
                        title: err,
                        icon: 'none',
                        duration: 3000,
                    });
                });
        },

        getOrderWxPay(orderNo, params) {
            let _this = this;
            let goPages;
            let orderId = _this.orderData.orderId;
            if (_this.type == 2) {
                // 我的问诊
                goPages = '/pagesSub-My/my/inquiryList';
            } else {
                // 现场开方或者开具处方 跳转到我的页面
                // goPages = '/pages/my/index';
                goPages = '/pages/my/drugOrderList?status=2';
            }
            // if (this.selectId != '0') {
            params = {
                ...params,
                uuid: this.orderData.uuid, //优惠券的uuid
            };
            // }
            wechatOrderPay(params)
                .then((res) => {
                    console.log(
                        res,
                        this.orderData,
                        _this.orderData.orderId,
                        orderId,
                        params.orderId,
                        '99999res-------'
                    );
                    // return
                    let jsConfig = res.data;
                    uni.requestPayment({
                        timeStamp: jsConfig.timeStamp,
                        nonceStr: jsConfig.nonceStr,
                        package: jsConfig.package,
                        signType: jsConfig.signType,
                        paySign: jsConfig.paySign,
                        // ticket: _this.productType==='normal'? null : jsConfig.ticket,
                        success: function (ress) {
                            uni.hideLoading();
                            // 调用接口查询通知接口支付成功，接口修改其订单状态
                            // orderData.orderNumber  || orderData.orderId
                            uni.showToast({
                                title: '支付成功',
                                duration: 3000,
                            });
                            _this.extraction = false;
                            if (_this.type == 2) {
                                return _this.$util.Tips(
                                    {
                                        title: '支付成功',
                                        icon: 'success',
                                    },
                                    {
                                        tab: 5,
                                        url: goPages,
                                    }
                                );
                            } else {
                                return _this.$util.Tips(
                                    {
                                        title: '支付成功',
                                        icon: 'success',
                                    },
                                    {
                                        tab: 5,
                                        url: goPages,
                                    }
                                );
                            }
                        },
                        fail: function (e) {
                            uni.hideLoading();
                            return _this.$util.Tips(
                                {
                                    title: '取消支付',
                                    icon: 'none',
                                },
                                {
                                    tab: 5,
                                    url: '/pages/my/drugOrderList?status=1',
                                }
                            );
                        },
                        complete: function (e) {
                            uni.hideLoading();
                            // console.log('支付完成999---')
                            //关闭当前页面跳转至订单状态
                            if (e.errMsg == 'requestPayment:cancel') {
                                return _this.$util.Tips(
                                    {
                                        title: '取消支付',
                                        icon: 'none',
                                    },
                                    {
                                        tab: 5,
                                        url: '/pages/my/drugOrderList?status=1',
                                    }
                                );
                            }
                        },
                    });
                })
                .catch((err) => {
                    _this.extraction = false;
                    uni.hideLoading();
                    return _this.$util.Tips({
                        title: err,
                    });
                });
        },
    },
};
</script>

<style lang="scss" scoped>
@import '@/static/css/style.css';

.dialogDiangnosis {
    padding: 30rpx;
    width: 250px;
    /* height: 385px; */
    background-color: #ffffff;
    border-radius: 20rpx;
}

.durgName {
    font-size: 30rpx;
    margin-top: 8rpx;
    text-overflow: -o-ellipsis-lastline;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    word-break: break-all;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* /deep/.uni-forms-item__label {
  width: 250rpx !important;
} */

.bg_image {
    background-image: url(../../../pagesSub/static/images/bg_menzhen@2x.png);
    height: 200rpx;
    background-size: 100% 100%;
    color: #ffffff;
    padding: 30rpx;
}

.appointment {
    font-weight: 600;
}

.prompt_font {
    font-size: 29rpx;
    margin-top: 5rpx;
}

.card_content {
    background-color: #ffffff;
    padding: 30rpx;
    margin: 30rpx;
    border-radius: 10rpx;
}

.card_one {
    margin-top: -100rpx;
}

.phone {
    margin-left: 30rpx;
}

.addressinfo {
    color: #3f3f3f;
    font-size: 30rpx;
    margin-top: 7rpx;
}

.personal_info {
    display: flex;
    justify-content: space-between;
}

.peopinfo {
    font-size: 32rpx;
}

.medical_content {
    display: flex;
    margin-top: 30rpx;
    border-bottom: 1rpx solid #fbfbfb;
    padding-bottom: 30rpx;
}

.pa_top {
    margin-top: 20rpx;
}

.personalfont {
    font-size: 31rpx;
}

.medical_img {
    width: 200rpx;
    height: 120rpx;
}

.medical_img image {
    width: 100%;
    height: 100%;
}

.medicalName {
    font-size: 32rpx;
}

.specification {
    font-size: 30rpx;
    margin-top: 10rpx;
}

.medical_right {
    margin-left: 30rpx;
    width: 100%;
}

.medical_title {
    display: flex;
    justify-content: space-between;
}

.medical_price {
    float: right;
    color: #d57667;
    font-weight: 600;
    font-size: 33rpx;
}

.real_payment {
    color: #d57667;
}

.add_medical {
    color: #acd4ce;
    text-align: center;
    font-size: 30rpx;
    margin-top: 40rpx;
}

.btn_appointment {
    margin-top: 40rpx;
    background: -webkit-linear-gradient(#77e2a4, #4ccdbc);
    color: #ffffff;
}

/* 支付按钮 */
.payment_button {
    width: 100%;
    display: flex;
    position: fixed;
    bottom: 0;
    height: 80rpx;
    background-color: #ffffff;
    padding-bottom: constant(safe-area-inset-bottom);
    padding-bottom: env(safe-area-inset-bottom);
    box-sizing: content-box;
}

.payment_button::after {
    content: '';
    display: block;
    clear: both;
}

.combined {
    font-size: 30rpx;
    text-align: center;
    line-height: 80rpx;
    width: 40%;
    background-color: #ffffff;
}

.combined_money {
    font-weight: bold;
    color: #5cc8b3;
}

.immediate {
    background: -webkit-linear-gradient(#77e2a4, #4ccdbc);
    color: #ffffff;
    line-height: 80rpx;
    font-size: 35rpx;
    width: 60%;
    text-align: center;
}

.customerService {
    width: 100%;
    height: 300rpx;
}

.customerService image {
    width: 120rpx;
    height: 120rpx;
    float: right;
    margin-right: 30rpx;
    margin-bottom: 50rpx;
}

.colse_content::after {
    display: block;
    clear: both;
    content: '';
}

.bth_green {
    border-top-right-radius: 40rpx;
    border-bottom-right-radius: 40rpx;
    border-top-left-radius: 40rpx;
    border-bottom-left-radius: 40rpx;
    border: 1rpx solid #4cccbf;
    background-color: #ffffff;
    color: #4cccbf;
    height: 50rpx;
    line-height: 50rpx;
    font-size: 24rpx;
    padding: 0 25rpx;
}

.invoice {
    display: flex;
    margin: 10rpx 0;
}

.btn_invoice {
    color: #ffffff;
    background-color: #4ccdbc;
    font-size: 30rpx;
    margin-top: 60rpx;
    margin-bottom: 30rpx;
}

/deep/.uni-easyinput__content-input.data-v-abe12412 {
    font-size: 30rpx;
    text-align: right;
}

.invoiceInput {
    margin-top: 30rpx;
}

.tag {
    color: #ffffff !important;
    background-color: #4cccbf !important;
}

/* .personal_info {
  display: flex;
  justify-content: space-between;
  font-size: 26rpx;
  padding: 30rpx;
  background-color: #ffffff;
} */
.specification {
    font-size: 30rpx;
    margin-top: 10rpx;
}

/* 弹出框 */
.inputDialog {
    width: 600rpx;
    border-radius: 10rpx;
    background-color: #ffffff;
}

.inputDialog > .title {
    text-align: center;
    padding: 30rpx;
    font-size: 32rpx;
    line-height: 50rpx;
}

.button-bottom {
    display: flex;
    border-top: 1px solid #f0f0f0;
}

.button-bottom view {
    width: 50%;
    padding: 20rpx 0 20rpx 0;
    font-size: 32rpx;
    text-align: center;
}

.cancel {
    border-right: 1px solid #f0f0f0;
}

/* 绿色字体 */
.green_words {
    color: #62c0ad;
}
</style>
